package com.myhome.money.base.javaio;

import java.io.*;

public class CharacterStream {

    public static void main(String[] args) throws IOException {
        readFromCharacter();
        writeToCharacter();
        readFromCharacter();
    }

    public static void writeToCharacter() throws IOException {
        String str ="hello world character";
        File file = new File("D:/javaio/io/test.txt");
        Writer writer = new FileWriter(file);
        writer.append(str).append(" ").append(str);
        writer.close();
    }

    public static void readFromCharacter() throws IOException {
        File file = new File("D:/javaio/io/test.txt");
        Reader reader = new FileReader(file);
        char[] chars = new char[(int)file.length()];
        reader.read(chars);
        String str = new String(chars);
        System.out.println("读取结果：" + str);
        reader.close();

    }


}
